package com.zby.scms.controller;

import com.github.pagehelper.PageHelper;
import com.zby.scms.entity.College;
import com.zby.scms.service.CollegeService;
import com.zby.scms.utils.BaseResult;
import com.zby.scms.utils.ResultUtil;
import io.swagger.annotations.ApiModel;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

/**
 * 用户信息(College)表控制层
 *
 * @author zhangboyi
 * @since 2019-12-31 15:27:37
 */
@Api(tags = "用户学院信息(College)")
@RestController
@RequestMapping("college")
public class CollegeController {
    /**
     * 服务对象
     */
    @Autowired
    private CollegeService collegeService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation(value = "根据id查询 用户信息")
    @GetMapping("selectOne/{id}")
    public BaseResult<College> selectOne(
            @ApiParam(value = " ID")
            @PathVariable("id") Integer id) {

        return ResultUtil.success("太难吃了吧",this.collegeService.queryById(id));

    }

    @ApiOperation(value = "查询所有信息")
    @GetMapping("findAll")
    public BaseResult<List<College>> findAll(Integer pageNum, Integer pagesize){
        System.out.println("List类型为："+List.class);
        System.out.println("List类型为："+ ArrayList.class);
        System.out.println("collegeService类型为："+collegeService.findAll().getClass());
        System.out.println("toString类型为："+collegeService.findAll().getClass().toString());

        PageHelper.startPage(pageNum, pagesize);

        return ResultUtil.success(collegeService.findAll());
    }

    @ApiOperation(value = "分页查询")
    @GetMapping("queryAllByLimit")
    public BaseResult<List<College>> queryAllByLimit(Integer pageNum, Integer pagesize){
        return ResultUtil.success(collegeService.queryAllByLimit(pageNum,pagesize));
    }


    @ApiOperation(value = "通过实体作为筛选条件查询")
    @GetMapping("queryAll")
    public BaseResult<List<College>> queryAll(College college){
        return ResultUtil.success(collegeService.queryAll(college));
    }


}